import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @Author: linzp
 * @Date: 2023/07/31/9:56
 */
public class demo0731 {



        public static void main(String[] args) {
            int corePoolSize = 10; // 线程池大小
            int maximumPoolSize = 10; // 最大线程池大小，这里和corePoolSize设置成一样
            long keepAliveTime = 0; // 线程空闲时间
            int queueCapacity = 10000; // 等待队列大小
            son son = new son();

            son.setPhone("136225511");

            ScheduledExecutorService executorService = Executors.newScheduledThreadPool(corePoolSize);

            // 定义要执行的延时任务
            Runnable delayedTask = () -> {
                for (int i = 0; i <10 ; i++) {
                    // 这里是要执行的任务逻辑
                    System.out.println("Delayed task executed!" + i);
                    System.out.println(son.getPhone());
                    try {
                        if (i==5){
                            son.setPhone("1111212");
                            throw new IllegalArgumentException("my Exception");
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                    }

                }

            };
//            System.out.println("111");

            // 延时时间
            long delayTime = 5; // 10秒后执行任务

            // 提交任务到线程池执行
            executorService.schedule(delayedTask, delayTime, TimeUnit.SECONDS);

            // 关闭线程池
            executorService.shutdown();
        }

}
